package com.goalias.feign.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserInfo implements Serializable {

    public static final ThreadLocal<UserInfo> threadLocal = new ThreadLocal<>();

    private Long id;
    private String nickName;
    private String phone;
    private String email;

    private String ip;
    private String address;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")//接收参数对应时间格式
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime lastTime;

    public static void set(UserInfo userInfo) {
        threadLocal.set(userInfo);
    }

    public static UserInfo get() {
        return threadLocal.get();
    }

    public static void remove() {
        threadLocal.remove();
    }
}
